package com.hhs.storage.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.hhs.storage.bean.GKf;
import com.hhs.storage.bean.GYm;
import com.hhs.storage.bean.Result;
import com.hhs.storage.service.GYmService;
import com.hhs.storage.util.QRCodeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shadow
 * @since 2020-06-19
 */
@RestController
@RequestMapping("/do/ym")
@Slf4j
public class GYmController {
    @Resource
    GYmService gYmService;
    @RequestMapping(value = "getdata")
    public Map<String, Object> getdata() {
        log.info("查询域名信息");
        EntityWrapper ew = new EntityWrapper<GYm>();
        ew.eq("id_",1);
        List result = gYmService.selectList(ew);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows", result);
        map.put("total",1);
        return map;
    }

    @RequestMapping(value = "edit")
    public Map<String, Object> saveOrUpdate(GYm gYm){
        log.info("编辑域名信息");

        try {
            //String text = "http://weifeng.nethangzhou.com/wf/weixin/getUserInfoCode";
            String text = gYm.getYname()+"/upload/appok.apk";
            gYm.setRePath("http://"+gYm.getYname()+"/upload/rwm_ok.jpg");
            gYmService.updateById(gYm);
            //生成带logo 的二维码
            //QRCodeUtil.encode(text, "d:/730.png", "d:/wfqrcode", true);
            //生成不带logo 的二维码
            QRCodeUtil.encode(text, "", "/upload", true);
        } catch (Exception e) {
            Result.failJsonResp(e.getMessage());
        }
        return Result.sucJsonResp(gYm.getRePath());
    }
}

